﻿<?php
class productComponent extends sfComponent{
	public function execute($request){
		$data = array('perpage' => 3);
		$data['pagination']	= array(
			'page'		=> intval($request->getParameter('page', 1)),
			'limit'		=> sfConfig::get('app_product_index_limit', 9),
			'total'		=> 0,
			'router'	=> 'product',
			'params'	=> array('level_id' => intval($request->getParameter('level_id', -1)) ,'cate_id' => intval($request->getParameter('cate_id', -1)), 'id' => intval($request->getParameter('id', -1)))
		);
		$data['filter'] = array(
			'filter_cate_id'		=> intval($request->getParameter('cate_id', -1)),
			'filter_level_id'		=> intval($request->getParameter('level_id', -1)),
			'filter_ids_notin' 	=> intval(intval($request->getParameter('id', -1)))
		);
		$data['act'] = strval($this->act);
		switch ($data['act']){
			case 'new': 
				$data['pagination']['limit']	= sfConfig::get('app_home_pro_limit', 9);
				$data['products'] = Products::getDataListFrontEnd(array(),$data['pagination']);
				break;
			case 'index':
				$data['products'] = Products::getDataListFrontEnd($data['filter'],$data['pagination']);
				$data['pagination']['total']		= Products::getDataListCountFrontEnd($data['filter']);
				break;
			case 'detail':
				$data['detail'] = Products::getDataByIdFrontEnd(intval($request->getParameter('page', 1)));
				$data['pagination']['limit']	= sfConfig::get('app_product_detail_limit', 6);
				$data['pagination']['total']		= Products::getDataListCountFrontEnd($data['filter']);
			
				$this->setVar('data', $data);
				break;
			case 'ref':
				$data['pagination']['limit']	= sfConfig::get('app_product_ref_limit', 3);
				$data['products'] = Products::getDataListFrontEnd($data['filter'],$data['pagination']);
				break;
		}
		
		$this->setVar('data', $data);
	}
}